﻿@model EMS.Calendar.ViewModels.CalendarViewModel
@using EMS.Calendar.Helpers

@{
    Layout.Title = T("Calendar Event").ToString();
    
    Style.Require("jqueryUI_DatePicker");
    Style.Require("jqueryUtils_TimePicker");
    
    Script.Require("jQueryUI_DatePicker").AtHead();
    Script.Require("jQueryUtils_TimePicker").AtHead();
    Script.Require("CalendarPart").AtFoot();

    string startDate = Model.StartDate == null ? "" : DateTime.Parse(Model.StartDate.ToString()).ToShortDateString(); // == "1/1/0001" ? "" : Model.StartDate.ToShortDateString();
    string startTime = Model.StartTime == null ? "" : DateTime.Parse(Model.StartTime.ToString()).ToShortTimeString(); // == "1/1/0001" ? "" : Model.StartTime.ToShortTimeString();
    string endDate = Model.EndDate == null ? "" : DateTime.Parse(Model.EndDate.ToString()).ToShortDateString(); // == "1/1/0001" ? "" : Model.EndDate.ToShortDateString();
    string endTime = Model.EndTime == null ? "" : DateTime.Parse(Model.EndTime.ToString()).ToShortTimeString(); // == "1/1/0001" ? "" : Model.EndTime.ToShortTimeString();
    
    if (startDate.Length < 10 &&
        !String.IsNullOrEmpty(startDate)) {
        startDate = "0" + startDate; // jQuery Date format always has a leading 0
    }

    if (endDate.Length < 10 &&
        !String.IsNullOrEmpty(endDate)) {
        endDate = "0" + endDate; // jQuery Date format always has a leading 0
    }
    
    if (startTime.Length < 8 && 
        !String.IsNullOrEmpty(startTime)) {
        startTime = "0" + startTime; // jQuery Time format always has a leading 0   
    }
    if (endTime.Length < 8 &&
        !String.IsNullOrEmpty(endTime)) {
        endTime = "0" + endTime; // jQuery Time format always has a leading 0   
    }
}

<fieldset>
    <legend>@T("Calendar Event")</legend>
    
    <label class="sub" for="EventOccurrence">@T("Event Occurrence")</label><br />
    @Html.DropDownListFor(m => m.EventOccurrence, Model.EventOccurrenceList, new { @class = "text" })<br />
    
    <div id="SingleEventPanel">
        <label id="StartDateLabel" class="sub" for="StartDate">@T("Start Time")</label>
        <input type="text" id="StartDate" name="StartDate" class="text" value="@startDate" />
        <input type="text" id="StartTime" name="StartTime" class="text" value="@startTime" />
        <label id="IsAllDayEventLabel" class="sub" for="IsAllDayEvent">@T("All Day Event")</label>
        @Html.CheckBoxFor(m => m.IsAllDayEvent, new { @class = "text" })<br />
    
        <label id="EndDateLabel" class="sub" for="EndDate">@T("End Time")</label>
        <input type="text" id="EndDate" name="EndDate" class="text" value="@endDate" />
        <input type="text" id="EndTime" name="EndTime" class="text" value="@endTime" />
    </div>

    <div id="RecurrenceEventPanel">
        <fieldset>
            <legend>Appointment time</legend>
            <label class="sub" for="StartTime">@T("Start Time")</label>
            <input type="text" id="StartTime" name="StartTime" class="text" value="@startTime" />
            <br />
            <label class="sub" for="EndTime">@T("End Time")</label>
            <input type="text" id="EndTime" name="EndTime" class="text" value="@endTime" />
        </fieldset>

        @*
        <div class="EventOccurrencePanel">
        
     
        <label class="sub" for="PeriodSpan">@T("Period Span")</label><br />
        @Html.TextBoxFor(m => m.PeriodSpan, new { @class = "text" })<br />

        <label class="sub" for="DayOfPeriod">@T("Day of Period")</label><br />
        @Html.TextBoxFor(m => m.DayOfPeriod, new { @class = "text" })<br />

        <label class="sub" for="DayInstance">@T("Day Instance")</label><br />
        @Html.DropDownListFor(m => m.DayInstance, Model.DayInstanceList, new { @class = "text" })<br />
        *@
        
        <fieldset>
            <legend>Recurrence pattern</legend>
            <label class="sub" for="Pattern">@T("Pattern")</label><br />
            @Html.DropDownListFor(m => m.Pattern, Model.PatternList, new { @class = "text" })<br />
    
            <label class="sub" for="MonthName">@T("Month Name")</label><br />
            @Html.DropDownListFor(m => m.MonthName, Model.MonthNameList, new { @class = "text" })<br />
            
            <div id="RecurrencePatternDaily">
                Every @Html.TextBoxFor(m => m.PeriodSpan, new { @class = "text" }) day(s)
                @*TODO: Need Every weekday option*@
            </div>

            <div id="RecurrencePatternWeekly">
                Recur every @Html.TextBoxFor(m => m.PeriodSpan, new { @class = "text" }) week(s) on:<br />
                <label class="sub" for="DayNames">@T("Day Name")</label><br />   
                @Html.CheckBoxList("DayNamesArray", Model.DayNameList)<br />
            </div>

            <div id="RecurrencePatternMonthly">
                Day @Html.TextBoxFor(m => m.DayOfPeriod, new { @class = "text" }) of every @Html.TextBoxFor(m => m.PeriodSpan, new { @class = "text" }) month(s)<br />
                The @Html.DropDownListFor(m => m.DayInstance, Model.DayInstanceList, new { @class = "text" }) 
            </div>

            <div id="RecurrencePatternYearly">
        
            </div>
        </fieldset>
        
        <fieldset>
            <legend>Range of recurrence</legend>
            <label class="sub" for="StartDate">@T("Start: ")</label>
            <input type="text" id="StartDate" name="StartDate" class="text" value="@startDate" />
            <br />
            <label class="sub" for="RecurrenceEnd">@T("End: ")</label>
            @Html.RadioButtonList("RecurrenceEnd", Model.RecurrenceEndList)
            <div style="position:relative; left:80px; top:-52px; max-height:0; height:0;">
                @Html.TextBoxFor(m => m.NumberOccurrences, new { @class = "text" }) 
                <label class="sub" for="NumberOccurrences">@T(" occurrences")</label>
            </div>
            <div style="position:relative; left:80px; top:-24px; max-height:0; height:0;">
                <input type="text" id="EndDate" name="EndDate" class="text" value="@endDate" />
            </div>
            <div style="clear:both; height:0; margin:0; padding:0;"></div>            
        </fieldset>
    
    </div>


</fieldset>